using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.Readers;

namespace TrainingManagement.api.Models.Data.CRUD.SkillSet
{
    public class SkillSetItemsSelectDataSource : QuerySource<int, List<BusinessObjects.Skill>>
    {
        public override List<BusinessObjects.Skill> Execute(int request)
        {
            const string skillSetItemsSelect = "dbo.training_api_SkillSetItemsSelect";
            var parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@SkillSetID", SqlDbType.Int){Value = request};

            using (var rdr = SqlHelper.ExecuteReader(
                ConnectionStrings.TrainingDb,
                CommandType.StoredProcedure,
                skillSetItemsSelect,
                parameters))
            {
                var results = new List<BusinessObjects.Skill>();
                var skillReader = new SkillDataReader();
                while (rdr.Read())
                {
                    results.Add(skillReader.Run(rdr));
                }
                return results;
            }
        }
    }
}